class TicketTemplatesController < ApplicationController
  before_filter :login_required

  def index
    @ticket_templates = TicketTemplate.find(:all, :order => :name)
  end

  def show
    @ticket_template = TicketTemplate.find(params[:id])
  end

  def new
    @heading = "New ticket template"
    @ticket_template = TicketTemplate.new
    @note_types = NoteType.find(:all, :order => "priority")
  end

  def duplicate
    @ticket_template = TicketTemplate.find(params[:id])
    if @ticket_template.duplicate
      flash[:notice] = "Ticket template was duplicated"
    else
      flash[:notice] = "Ticket template wasn't duplicated"
    end
    redirect_to ticket_templates_url
  end

  def create
    @ticket_template = TicketTemplate.new(params[:ticket_template])
    if @ticket_template.save
      flash[:notice] = 'TicketTemplate was successfully created.'
      redirect_to ticket_templates_url
    else
      @heading = "New ticket template"

      render :action => 'new'
    end
  end

  def edit
    @heading = "Editing ticket template"
    @ticket_template = TicketTemplate.find(params[:id])
  end

  def update
    @ticket_template = TicketTemplate.find(params[:id])

    if @ticket_template.update_attributes(params[:ticket_template])
      flash[:notice] = 'Ticket template was successfully updated'
      redirect_to ticket_templates_url
    else
      render :action => 'edit'
    end
  end

  def destroy
    wc = TicketTemplate.find(params[:id])
    wc.destroy
    redirect_to ticket_templates_url
  end
  
end
